home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2001 May / may_2001.iso / intercd / root / Multimedia / ^DivX_Article / virtualdub / VirtualDub-source-1_4d / MonoBitmap.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-03-20  |  2.5 KB  |  77 lines

  1. //    VirtualDub - Video processing and capture application
  2. //    Copyright (C) 1998-2001 Avery Lee
  3. //
  4. //    This program is free software; you can redistribute it and/or modify
  5. //    it under the terms of the GNU General Public License as published by
  6. //    the Free Software Foundation; either version 2 of the License, or
  7. //    (at your option) any later version.
  8. //
  9. //    This program is distributed in the hope that it will be useful,
  10. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. //    GNU General Public License for more details.
  13. //
  14. //    You should have received a copy of the GNU General Public License
  15. //    along with this program; if not, write to the Free Software
  16. //    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18. #include "MonoBitmap.h"
  19.  
  20. MonoBitmap::MonoBitmap(HDC hdcRef, int width, int height, COLORREF crFore, COLORREF crBack) {
  21.     HDC hdcDisplay = NULL;
  22.  
  23.     if (!hdcRef)
  24.         hdcRef = hdcDisplay = CreateDC("DISPLAY", NULL, NULL, NULL);
  25.  
  26.     hdcCompat = CreateCompatibleDC(hdcRef);
  27.  
  28.     iPitch = ((width + 31)/32)*4;
  29.  
  30.     bi.bi.bmiHeader.biSize            = sizeof(BITMAPINFOHEADER);
  31.     bi.bi.bmiHeader.biWidth            = width;
  32.     bi.bi.bmiHeader.biHeight        = height;
  33.     bi.bi.bmiHeader.biPlanes        = 1;
  34.     bi.bi.bmiHeader.biBitCount        = 1;
  35.     bi.bi.bmiHeader.biCompression    = BI_RGB;
  36.     bi.bi.bmiHeader.biSizeImage        = iPitch*height;
  37.     bi.bi.bmiHeader.biXPelsPerMeter    = 100;
  38.     bi.bi.bmiHeader.biYPelsPerMeter    = 100;
  39.     bi.bi.bmiHeader.biClrUsed        = 2;
  40.     bi.bi.bmiHeader.biClrImportant    = 2;
  41.     bi.bi.bmiColors[0].rgbBlue    = GetBValue(crBack);
  42.     bi.bi.bmiColors[0].rgbGreen    = GetGValue(crBack);
  43.     bi.bi.bmiColors[0].rgbRed    = GetRValue(crBack);
  44.     bi.bi.bmiColors[1].rgbBlue    = GetBValue(crFore);
  45.     bi.bi.bmiColors[1].rgbGreen    = GetGValue(crFore);
  46.     bi.bi.bmiColors[1].rgbRed    = GetRValue(crFore);
  47.  
  48.     hbm = CreateDIBSection(hdcCompat, &bi.bi, DIB_RGB_COLORS, &lpvBits, NULL, 0);
  49.     SelectObject(hdcCompat, hbm);
  50.  
  51.     if (hdcDisplay) DeleteDC(hdcDisplay);
  52.  
  53. }
  54.  
  55. MonoBitmap::~MonoBitmap() {
  56.     DeleteDC(hdcCompat);
  57.     DeleteObject(hbm);
  58. }
  59.  
  60. void MonoBitmap::Clear() {
  61.     GdiFlush();
  62.     memset(lpvBits, 0, bi.bi.bmiHeader.biSizeImage);
  63. }
  64.  
  65. void MonoBitmap::BitBlt(HDC hdcDest, LONG x, LONG y) {
  66.     BitBlt(hdcDest, x, y, 0, 0, bi.bi.bmiHeader.biWidth, bi.bi.bmiHeader.biHeight);
  67. }
  68.  
  69. void MonoBitmap::BitBlt(HDC hdcDest, LONG dx, LONG dy, LONG sx, LONG sy, LONG w, LONG h) {
  70.     ::BitBlt(hdcDest,
  71.         dx, dy,
  72.         w, h,
  73.         hdcCompat,
  74.         sx, sy,
  75.         SRCCOPY);
  76. }
  77.